'use strict';
const db = uniCloud.database()
const weight = db.collection('weight_data')
exports.main = async (event, context) => {
	const res = await weight.where({
		openid: event.openid,
		date: event.date
	}).get()
	let data;
	if (res.affectedDocs > 0) {
		data = await weight.where({
			openid: event.openid,
			date: event.date
		}).update({
			weight: event.weight
		})
	} else {
		data = await weight.add(event)
	}
	const msg = data.updated ? '修改成功' : '新增成功'
	//返回数据给客户端
	return {
		code: 200,
		msg: msg
	}
};